// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.16.10
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// SysTenantUpdateFields 修改租户列表字段过滤
type SysTenantUpdateFields struct {
	Name          string      `json:"name"          dc:"租户名"`
	ContactUserId int64       `json:"contactUserId" dc:"联系人用户"`
	Status        int         `json:"status"        dc:"租户状态"`
	Website       string      `json:"website"       dc:"绑定域名"`
	PackageId     int64       `json:"packageId"     dc:"租户套餐"`
	ExpireTime    *gtime.Time `json:"expireTime"    dc:"过期时间"`
	UpdatedBy     int64       `json:"updatedBy"     dc:"更新者"`
}

// SysTenantInsertFields 新增租户列表字段过滤
type SysTenantInsertFields struct {
	Name          string      `json:"name"          dc:"租户名"`
	ContactUserId int64       `json:"contactUserId" dc:"联系人用户"`
	Status        int         `json:"status"        dc:"租户状态"`
	Website       string      `json:"website"       dc:"绑定域名"`
	PackageId     int64       `json:"packageId"     dc:"租户套餐"`
	ExpireTime    *gtime.Time `json:"expireTime"    dc:"过期时间"`
	CreatedBy     int64       `json:"createdBy"     dc:"创建者"`
}

// SysTenantEditInp 修改/新增租户列表
type SysTenantEditInp struct {
	entity.SysTenant
}

func (in *SysTenantEditInp) Filter(ctx context.Context) (err error) {
	// 验证租户名
	if err := g.Validator().Rules("required").Data(in.Name).Messages("租户名不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证联系人用户
	if err := g.Validator().Rules("required").Data(in.ContactUserId).Messages("联系人用户不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证租户状态
	if err := g.Validator().Rules("required").Data(in.Status).Messages("租户状态不能为空").Run(ctx); err != nil {
		return err.Current()
	}
	if err := g.Validator().Rules("in:1,2").Data(in.Status).Messages("租户状态值不正确").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证租户套餐
	if err := g.Validator().Rules("required").Data(in.PackageId).Messages("租户套餐不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证过期时间
	if err := g.Validator().Rules("required").Data(in.ExpireTime).Messages("过期时间不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type SysTenantEditModel struct{}

// SysTenantDeleteInp 删除租户列表
type SysTenantDeleteInp struct {
	Id interface{} `json:"id" v:"required#租户编号不能为空" dc:"租户编号"`
}

func (in *SysTenantDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantDeleteModel struct{}

// SysTenantViewInp 获取指定租户列表信息
type SysTenantViewInp struct {
	Id int64 `json:"id" v:"required#租户编号不能为空" dc:"租户编号"`
}

func (in *SysTenantViewInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantViewModel struct {
	entity.SysTenant
}

// SysTenantListInp 获取租户列表列表
type SysTenantListInp struct {
	form.PageReq
	Name          string        `json:"name"          dc:"租户名"`
	ContactName   string        `json:"contactName"   dc:"联系人"`
	ContactMobile string        `json:"contactMobile" dc:"联系手机"`
	Status        int           `json:"status"        dc:"租户状态"`
	PackageId     int64         `json:"packageId"     dc:"租户套餐"`
	CreatedAt     []*gtime.Time `json:"createdAt"     dc:"创建时间"`
}

func (in *SysTenantListInp) Filter(ctx context.Context) (err error) {
	return
}

type SysTenantListModel struct {
	Id            int64       `json:"id"            dc:"租户编号"`
	Name          string      `json:"name"          dc:"租户名"`
	ContactName   string      `json:"contactName"   dc:"联系人"`
	ContactMobile string      `json:"contactMobile" dc:"联系手机"`
	Status        int         `json:"status"        dc:"租户状态"`
	Website       string      `json:"website"       dc:"绑定域名"`
	PackageId     int64       `json:"packageId"     dc:"租户套餐"`
	ExpireTime    *gtime.Time `json:"expireTime"    dc:"过期时间"`
	AccountCount  int         `json:"accountCount"  dc:"账号数量"`
	CreatedAt     *gtime.Time `json:"createdAt"     dc:"创建时间"`
}

// SysTenantExportModel 导出租户列表
type SysTenantExportModel struct {
	Id            int64       `json:"id"            dc:"租户编号"`
	Name          string      `json:"name"          dc:"租户名"`
	ContactUserId int64       `json:"contactUserId" dc:"联系人用户"`
	ContactName   string      `json:"contactName"   dc:"联系人"`
	ContactMobile string      `json:"contactMobile" dc:"联系手机"`
	Status        int         `json:"status"        dc:"租户状态"`
	Website       string      `json:"website"       dc:"绑定域名"`
	PackageId     int64       `json:"packageId"     dc:"租户套餐"`
	ExpireTime    *gtime.Time `json:"expireTime"    dc:"过期时间"`
	AccountCount  int         `json:"accountCount"  dc:"账号数量"`
	CreatedBy     int64       `json:"createdBy"     dc:"创建者"`
	CreatedAt     *gtime.Time `json:"createdAt"     dc:"创建时间"`
	UpdatedBy     int64       `json:"updatedBy"     dc:"更新者"`
	UpdatedAt     *gtime.Time `json:"updatedAt"     dc:"更新时间"`
}

// SysTenantStatusInp 更新租户列表状态
type SysTenantStatusInp struct {
	Id     int64 `json:"id" v:"required#租户编号不能为空" dc:"租户编号"`
	Status int   `json:"status" dc:"状态"`
}

func (in *SysTenantStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("租户编号不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type SysTenantStatusModel struct{}